use std::{
    fmt::{Display, Write},
    str::FromStr,
};
use crate::core::error::convert_error::ConvertError;

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum BuildTarget {
    Android,
    IOS,
    Windows,
}

impl Display for BuildTarget {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let str = match self {
            BuildTarget::Android => "Android ",
            BuildTarget::IOS => "IOS ",
            BuildTarget::Windows => "Windows ",
        }.to_string();
        write!(f, "{}", str)
    }
}

impl FromStr for BuildTarget {
    type Err = ConvertError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let lower = s.to_lowercase();
        if lower == "android" {
            Ok(BuildTarget::Android)
        } else if lower == "ios" {
            Ok(BuildTarget::IOS)
        } else if lower == "windows" {
            Ok(BuildTarget::Windows)
        } else {
            Err(ConvertError::StringToEnum {
                type_name: "BuildTarget".to_string(),
                value: lower,
            })
        }
    }
}
